using System.Globalization;
using GamFi.Admin.API.Application.Models;
using Microsoft.AspNetCore.Localization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options;

namespace GamFi.Admin.API.Application;

public static class Entry
{
    public static void AddApplicationLayer(this IServiceCollection serviceCollection, IConfiguration configuration)
    {
        serviceCollection.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(Entry).Assembly));
        serviceCollection.AddLocalization();
        serviceCollection.AddRequestLocalization(x =>
        {
            x.DefaultRequestCulture = new RequestCulture("en");
            x.ApplyCurrentCultureToResponseHeaders = true;
            x.SupportedCultures = new List<CultureInfo> {new("ru"), new("en")};
            x.SupportedUICultures = new List<CultureInfo> {new("ru"), new("en")};
        });
        serviceCollection.AddSingleton<IStringLocalizerFactory, ResourceManagerStringLocalizerFactory>();
        serviceCollection.AddSingleton(typeof(IStringLocalizer<string>), typeof(StringLocalizer<string>));
    }
}